// store/modules/flight.js
import { getFlightByCFCityAndDDCity } from '@/api/flight.js';

const state = {
    flights: []
};

const mutations = {
    SET_FLIGHTS(state, flights) {
        state.flights = flights;
    }
};

const actions = {
    async searchFlights({ commit }, { cfcity, ddcity }) {
        try {
            const response = await getFlightByCFCityAndDDCity(cfcity, ddcity);
            if (response.code === 1) {
                commit('SET_FLIGHTS', response.data);
            }
        } catch (error) {
            console.error('Error fetching flight data:', error);
        }
    }
};

const getters = {
    flights: state => state.flights
};

export default {
    namespaced: true,
    state,
    mutations,
    actions,
    getters
};
